package com.yjz.springcloudconsumer01;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
/*启用服务注册与发现*/
@EnableDiscoveryClient
/*启用feign进行远程调用*/
@EnableFeignClients
/*启用Hystrix Dashboard*/
@EnableHystrixDashboard
/*熔断器*/
@EnableCircuitBreaker
public class SpringcloudConsumer01Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudConsumer01Application.class, args);
    }


    /**
     * 不加这个HystrixDashboard 大盘不管用
     * @return
     */
    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}

